define(["../common"], function() {
	var $form = $("#form_register");
	
	var formCfg = {
		fields: {
			name: "用户名:required;username;remote[" + g_domain + "/member/checkName]",
			password: "密码:required;password",
			"#password2": "确认密码:required;match(password)",
			captcha: "验证码:required;remote[" + g_domain + "/captcha/check]"
		},
	}
	
	requirePlugin(["validator"], function() {
		$form.validator(formCfg);
	});
	
	$("a.checkbox").click(function() {
		$(this).trigger('check');
		return false;
	});
	
	$form.on('valid.form', function(e, form){
		$form.loadMsg("正在注册...");
		$.post(g_domain + "/member/registerDo/json", $form.serialize(), function(data){
			if (data.status != 0) {
				$form.failMsg(data.message);
				return;
			} 
			$form.infoMsg("注册成功! 现在返回登录页面...");
			setTimeout(function() {
				location.href = g_domain + "/member/login";
			},2000);
		});
	});
	
});